#ifndef TOOLSABILITY_H
#define TOOLSABILITY_H

#include "IMcpCapability.h"
#include "protocol/IProtocolHandler.h"

#include <QJsonObject>
#include <QJsonArray>
#include <QMap>
#include <memory>

/**
 * @brief Tools capability implementation
 * 
 * Manages tool methods with specific validation for tool parameters and schema.
 * Tools capability requires name, description, and parameter schema validation.
 */
class ToolsCapability : public IMcpCapability
{
public:
    struct Method {
        QString name;
        QMap<QString, QString> paramTypeMap;
        QStringList requiredList;
    };

public:
    ToolsCapability();
    ~ToolsCapability() override = default;

public:// ToolsCapability
    QString prefix() const override;
    QJsonObject capability() const override;
    void setCapability(const QString& capability, const bool enable = true) override;
    QJsonArray list() const override;
    bool addMethod(const CapabilityMethod& method) override;
    void clearMethod() override;
    QJsonObject doRequest(const QJsonObject& request) override;
    
    /**
     * @brief Set the message serializer for testing purposes
     * @param serializer - pointer to the message serializer implementation
     */
    void setSerializer(std::unique_ptr<IMessageSerializer> serializer);

private:
    /**
     * @brief Check if a tool method is valid
     * @param method - JSON object containing tool method configuration
     * @return int - the error code, 0 if method is valid, false otherwise
     */
    int checkMethodValidate(const QJsonObject& request, QString* msg = nullptr) const;

private:
    QJsonObject mCapability;
    QJsonArray mToolsList;
    std::unique_ptr<IMessageSerializer> mSerializer;
private:
    QMap<QString, Method> mMethodMap;
    QMap<QString, std::shared_ptr<Task>> mTaskMap;
};

#endif // TOOLSABILITY_H
